Reference for Wiring version 0024+. If you have a previous version, use the reference included with your software. If you see any errors or have any comments, let us know.

Name

array

Examples
// declaring an array of integers
int numbers[] = { 90, 150, 30 };
int a, b;

void setup() {
  a = numbers[0] + numbers[1]; // Sets variable a to 240
  b = numbers[1] + numbers[2]; // Sets variable b to 180
}

// different ways of declaring arrays of chars
char string1[15];
char string2[7] = {'h', 'e', 'l', 'l', 'o', '!'};
char string3[7] = {'h', 'e', 'l', 'l', 'o', '!', ''};
char string4[] = "hello there!";

int a = 10;
char *string5 = new char[a+1];  // allocates an array for holding 10 characters (last position is for holding the  or NULL string terminator

// ... 

delete [] string5;  // releases the memory space allocated for string5
Description An array is a list of data. It is possible to have an array of any type of data. Each piece of data in an array is identified by an index number representing its position in the array. The first element in the array is [0], the second element is [1], and so on.
Syntax
datatypevar[]
var[element] = value
Parameters
datatype any primitive or compound datatype, including user defined classes
var any valid variable name
element int: must not exceed the length of the array - 1
value data to assign to the array element, must be the same datatype as the array
Usage Application
Related new
delete
Updated on October 21, 2009 08:26:29pm PDT

Creative Commons License